home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Draw / Sources / BaseShp.h < prev    next >
Encoding:
Text File  |  1996-12-16  |  10.3 KB  |  339 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                BaseShp.h
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef BASESHP_H
  13. #define BASESHP_H
  14.  
  15. #ifndef CONSTANT_H
  16. #include "Constant.h"
  17. #endif
  18.  
  19. #ifndef FWSELECT_H
  20. #include "FWSelect.h"
  21. #endif
  22.  
  23. #ifndef FWSCPTBL_H
  24. #include "FWScptbl.h"
  25. #endif
  26.  
  27. #ifndef FWPAT_H
  28. #include "FWPat.h"
  29. #endif
  30.  
  31. #ifndef FWINK_H
  32. #include "FWInk.h"
  33. #endif
  34.  
  35. #ifndef FWSTYLE_H
  36. #include "FWStyle.h"
  37. #endif
  38.  
  39. #ifndef FWPOINT_H
  40. #include "FWPoint.h"
  41. #endif
  42.  
  43. #ifndef FWRECT_H
  44. #include "FWRect.h"
  45. #endif
  46.  
  47. #ifndef FWRUNTYP_H
  48. #include "FWRunTyp.h"
  49. #endif
  50.  
  51. #ifndef FWMREFCT_H
  52. #include "FWMRefCt.h"
  53. #endif
  54.  
  55. #ifndef FWTCOLL_H
  56. #include "FWTRCtCl.h"
  57. #endif
  58.  
  59. //========================================================================================
  60. // Forward Declarations
  61. //========================================================================================
  62.  
  63. class ODFacet;
  64. class ODShape;
  65. class CDrawPart;
  66. class CDrawPublishLink;
  67. class CDrawSubscribeLink;
  68. class FW_CGraphicContext;
  69. class FW_CMouseEvent;
  70. class FW_CRectShape;
  71. class FW_CPromise;
  72. class CDrawFacetClipper;
  73. class CDrawFrame;
  74. class FW_CView;
  75. class CGroupShape;
  76.  
  77. //========================================================================================
  78. // Constants
  79. //========================================================================================
  80.  
  81. enum ShapeType {
  82.     kLineShape = 1,
  83.     kRectShape = 2,
  84.     kOvalShape = 3,
  85.     kRRectShape = 4,
  86.     kTextShape = 5,
  87.     kProxyShape = 6,
  88.     kGroupShape = 7
  89. };
  90.  
  91. //========================================================================================
  92. // Global Methods
  93. //========================================================================================
  94.  
  95. inline FW_Fixed CalcHandlePenSize(FW_Fixed zoomFactor)
  96. {
  97.     return (FW_kFixedPos2 + FW_ODFixedToFixed(0x00008000)) / zoomFactor;
  98. }
  99.  
  100. //========================================================================================
  101. // class CBaseShape
  102. //========================================================================================
  103.  
  104. class CBaseShape : public FW_MScriptable, public FW_MRefCount
  105. {
  106. public:
  107.     FW_DECLARE_CLASS
  108.     FW_DECLARE_AUTO(CBaseShape)
  109.  
  110. protected:
  111.     CBaseShape(CDrawPart* drawPart, short numberOfHandles, unsigned short shapeType, unsigned short renderVerb);
  112.     CBaseShape(CDrawPart* drawPart, FW_CReadableStream& archive);
  113.  
  114. public:     // Should really be private but has to be public because of the ODF emulated exception
  115.     virtual ~CBaseShape();
  116.     
  117. public:
  118.  
  119.     virtual void        Removed(Environment* ev);
  120.     virtual void        Deleted(Environment* ev);
  121.     
  122.     // ----- Drawing -----
  123.     void                Invalidate(Environment* ev);
  124.     virtual void         RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc) = 0;
  125.     void                RenderHandles(FW_CGraphicContext& gc, FW_Fixed zoomFactor);
  126.     void                InvalidateHandles(Environment* ev, FW_CView* contentView, ODShape* workingShape, FW_Fixed penSize);
  127.     
  128.     // ----- Shape setting -----
  129.     FW_Fixed            GetPenSize() const;
  130.         
  131.     // ----- Selection -----
  132.     virtual FW_Boolean    HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const = 0;
  133.     FW_Boolean            InSelectionRect(const FW_CRect& rect) const;
  134.     
  135.     short                WhichHandle(FW_CGraphicContext& gc, const FW_CPoint& mouse, FW_Fixed zoomFactor) const;
  136.     
  137.     void                 CalcHandle(short whichHandle, FW_CRectShape* handle, FW_Fixed penSize) const;
  138.     void                CalcHandle(short whichHandle, FW_CRect& rect, FW_Fixed penSize) const;
  139.  
  140.     virtual void        SelectShape(Environment *ev, FW_Boolean state);
  141.     FW_Boolean            IsSelectedShape() const
  142.                             {return fSelected;}
  143.  
  144.     virtual void        RestoreShape(Environment *ev);
  145.     
  146.     // ----- Creation -----
  147.     virtual void         TrackFeedback(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc, const FW_CPoint& anchorPoint, const FW_CPoint& currentPoint, FW_Boolean erase);
  148.     virtual void         SetShapeGeometry(const FW_CPoint& anchorPoint, const FW_CPoint& currentPoint) = 0;
  149.  
  150.     // ----- Promises -----
  151.     void                Promised(FW_StorageKinds storageKind, FW_Boolean state);
  152.     FW_Boolean            IsPromised() const
  153.                             {return fPromised != 0;}
  154.     void                 CheckPromise(Environment* ev);
  155.  
  156.     // ----- Drag -----
  157.     virtual void        OffsetShape(Environment *ev, FW_Fixed xDelta, FW_Fixed yDelta) = 0;
  158.     
  159.     // ----- Resize -----
  160.     FW_CStyle            GetResizeStyle() const;
  161.     virtual void        ResizeFeedback(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style, 
  162.                                         short whichHandle, const FW_CPoint& mouseLoc) = 0;
  163.     virtual void        GetMapRects(short whichHandle, const FW_CPoint& lastLocation,
  164.                                     FW_CRect& srcRect, FW_CRect& dstRect) = 0;
  165.     virtual void        GetHandleCenter(short whichHandle, FW_CPoint& center) const = 0;
  166.     virtual void        MapShape(Environment *ev, const FW_CRect& srcRect, const FW_CRect& dstRect) = 0;
  167.     
  168.     void                GetUpdateBox(Environment* ev, ODShape *updateBox) const;
  169.     void                GetUpdateBox(FW_CRect& updateBox) const;
  170.     void                GetDragRect(FW_CRect& dragRect) const;
  171.     
  172.     virtual ODShape*    CreateShapeOutline(Environment *ev) = 0;
  173.     virtual ODShape*    AcquireClipShape(Environment* ev);
  174.     virtual ODShape*    CalcClipShape(Environment* ev) = 0;
  175.     virtual FW_CRect    GetRectGeometry() const = 0;
  176.     
  177.     virtual void        SubtractToWorkingClip(Environment *ev, 
  178.                                             CDrawFacetClipper* facetClipper, 
  179.                                             ODFacet* containingFacet, 
  180.                                             ODShape* workingClip,
  181.                                             ODShape* tempShape,
  182.                                             ODShape* limitShape);
  183.                                                 
  184.     // ----- Persistence -----
  185.     virtual void         Flatten(FW_CWritableStream& archive);
  186.     
  187.     // ----- Cache -----
  188.     void                ClearCache(Environment* ev);
  189.     
  190.     // ----- Linking -----
  191.     virtual void        SetPublishLink(Environment* ev, 
  192.                             CDrawPublishLink* publishLink);
  193.     CDrawPublishLink*    GetPublishLink() const
  194.                             {return fPublishLink;}
  195.     FW_Boolean            IsPublished() const
  196.                             {return fPublishLink != NULL;}
  197.                             
  198.     virtual void        SetSubscribeLink(Environment* ev, 
  199.                             CDrawSubscribeLink* subscribeLink);
  200.     CDrawSubscribeLink*    GetSubscribeLink() const
  201.                             {return fSubscribeLink;}
  202.     FW_Boolean            IsSubscribed() const
  203.                             {return fSubscribeLink != NULL;}
  204.     virtual FW_Boolean    IsInLinkDestination(Environment* ev);
  205.                             
  206.     short                GetExternalizationIndex()
  207.                             { return fExternalizationIndex; }
  208.     void                SetExternalizationIndex(short index)
  209.                             { fExternalizationIndex = index; }
  210.                             
  211.     // ----- Getters/Setters -----
  212.     virtual FW_Boolean    SetFrozen(FW_Boolean state);
  213.     virtual FW_Boolean IsFrozen() const;
  214.     
  215.     FW_Boolean            HasFillStyle() const
  216.                             {return (fRenderVerb & kFillOnly) != 0;}
  217.     FW_Boolean            FillOnly() const
  218.                             {return fRenderVerb == kFillOnly;}
  219.     FW_Boolean            HasFrameStyle() const
  220.                             {return (fRenderVerb & kFrameOnly) != 0;}
  221.     FW_Boolean            FrameOnly() const
  222.                             {return fRenderVerb == kFrameOnly;}
  223.     FW_Boolean            HasFrameAndFillStyle() const
  224.                             {return (fRenderVerb == kFillFrame);}
  225.                                                         
  226.     void                GetColor(FW_Boolean fill, FW_CColor& color);
  227.     FW_CPattern            GetPattern(FW_Boolean fill);
  228.     unsigned short        GetRenderVerb()
  229.                             { return fRenderVerb; };
  230.                         
  231.     short                GetNumberOfHandles() const
  232.                             {return fNumberOfHandles;}
  233.     ShapeType            GetShapeType() const
  234.                             {return (ShapeType)fShapeType;}
  235.     
  236.     void                SetFrameInk(const FW_CInk& ink)
  237.                             {fFrameInk = ink;}
  238.     void                SetFrameStyle(const FW_CStyle& style)
  239.                             {fFrameStyle = style;}
  240.     void                SetFillInk(const FW_CInk& ink)
  241.                             {fFillInk = ink;}
  242.     void                SetFillStyle(const FW_CStyle& style)
  243.                             {fFillStyle = style;}
  244.     
  245.     FW_Boolean            IsGrouped() const
  246.                             {return fGroup != NULL;}
  247.     CGroupShape*        GetGroup()
  248.                             {return fGroup;}
  249.     void                SetGroupedState(CGroupShape* group)
  250.                             {fGroup = group;}
  251.                                             
  252.     virtual void        ChangeFrameColor(Environment* ev, const FW_CColor& color);
  253.     virtual void        ChangeFramePattern(Environment* ev, const FW_CPattern& pattern);
  254.  
  255.     virtual void        ChangeFillColor(Environment* ev, const FW_CColor& color);
  256.     virtual void        ChangeFillPattern(Environment* ev, const FW_CPattern& pattern);
  257.  
  258.     virtual void        ChangePenSize(Environment* ev, FW_Fixed newPenSize);
  259.     virtual void        ChangeRenderVerb(Environment* ev, unsigned short renderVerb);
  260.  
  261.     FW_CInk                UnshareInk(const FW_CInk& ink) const;
  262.     FW_CStyle            UnshareStyle(const FW_CStyle& style) const;
  263.     
  264.     virtual void        AdjustRectForPenSize(FW_CRect& rect, FW_Fixed penSize) const;
  265.  
  266.     // ----- Semantic Object -----
  267.     
  268.     virtual ODDescType    GetObjectClass() const;
  269.     
  270.     virtual long        AcquireScriptable();
  271.     
  272.     virtual long        ReleaseScriptable();
  273.     
  274.     virtual FW_Boolean    HasProperty(ODDescType whichProperty) const;
  275.     
  276.     virtual FW_Boolean    GetProperty(Environment* ev, 
  277.                                     FW_CPart* part, 
  278.                                     FW_CDesc& propertyValue, 
  279.                                     ODDescType whichProperty, 
  280.                                     ODDescType desiredType) const;
  281.                                     
  282.     virtual void        SetProperty(Environment* ev, 
  283.                                     FW_CPart* part, 
  284.                                     FW_CDesc& propertyValue, 
  285.                                     ODDescType whichProperty);    
  286.                                                         
  287.     virtual void        GetUndoStrings(Environment* ev,
  288.                                     FW_CPart* part,
  289.                                     ODDescType whichProperty, 
  290.                                     FW_CString& undoString, 
  291.                                     FW_CString& redoString) const;
  292.     
  293.     // ----- Purge -----
  294.     virtual void        MakePurgeable(Environment* ev, CDrawFrame* drawFrame, const FW_CRect& bounds);
  295.     
  296.     // ----- Archiving -----
  297.     static void*         Read(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  298.     static void         Write(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object);
  299.     virtual void ShapeCommitPasteDone(Environment* ev);
  300.  
  301.     void                 InitStatic();
  302.     
  303. public:        
  304.     static FW_CRectShape*                gWorkingHandle;
  305.     static unsigned long                 gShapeCount;
  306.  
  307. protected:
  308.     CDrawPart*                            fDrawPart;
  309.     unsigned short                        fPromised;
  310.     
  311.     FW_CInk                                fFrameInk;
  312.     FW_CInk                                fFillInk;
  313.     FW_CStyle                            fFrameStyle;
  314.     FW_CStyle                            fFillStyle;
  315.     
  316.     unsigned short                        fRenderVerb;
  317.  
  318.     unsigned short                        fShapeType;
  319.     
  320.     FW_Boolean                            fSelected;
  321.     short                                fNumberOfHandles;
  322.     CDrawPublishLink*                    fPublishLink;
  323.     CDrawSubscribeLink*                    fSubscribeLink;
  324.     short                                fExternalizationIndex;    // used by links to identify their shapes
  325.     
  326.     ODShape*                            fClipShape;
  327.     
  328.     CGroupShape*                        fGroup;
  329. };
  330.  
  331. //========================================================================================
  332. // TypeDefs
  333. //========================================================================================
  334.  
  335. typedef FW_TRefCountedCollection<CBaseShape> CShapeCollection;
  336. typedef FW_TRefCountedCollectionIterator<CBaseShape> CShapeCollectionIterator;
  337.  
  338. #endif
  339.